{{ 'component-image-with-text.css' | asset_url | stylesheet_tag }}

<div class="bgI-with-text">
      <div class="image-with-text {% if section.settings.full_width %}image-with-text--full-width{% else %}page-width{% endif %} color-scheme-{{ section.settings.color_scheme }}">
        <div class="bg-content" >
          <div class="image-with-text__grid color-{{ section.settings.color_scheme }} grid grid--gapless grid--1-col grid--2-col-tablet gradient{% if section.settings.layout == 'text_first' %} image-with-text__grid--reverse{% endif %}">
            <div class="grid__item">
              <div class="image-with-text__media image-with-text__media--{{ section.settings.height }} {% if section.settings.image != blank %}media{% else %}image-with-text__media--placeholder placeholder{% endif %}"
                {% if section.settings.height == 'adapt' and section.settings.image != blank %} style="padding-bottom: {{ 1 | divided_by: section.settings.image.aspect_ratio | times: 100 }}%;"{% endif %}
              >
                {%- if section.settings.image != blank -%}
                  <img
                    srcset="
                     {%- if section.settings.image.width >= 323 -%}{{ section.settings.image | img_url: '323x' }} 323w,{%- endif -%}
                     {%- if section.settings.image.width >= 360 -%}{{ section.settings.image | img_url: '360x' }} 360w,{%- endif -%}
                     {%- if section.settings.image.width >= 539 -%}{{ section.settings.image | img_url: '539x' }} 539w,{%- endif -%}
                      {%- if section.settings.image.width >= 750 -%}{{ section.settings.image | img_url: '535x' }} 535w,{%- endif -%}
                      {%- if section.settings.image.width >= 1070 -%}{{ section.settings.image | img_url: '535x' }} 535w,{%- endif -%}
                      {%- if section.settings.image.width >= 1500 -%}{{ section.settings.image | img_url: '1500x' }} 1500w,{%- endif -%}
                      {{ section.settings.image | img_url: 'master' }} {{ section.settings.image.width }}w"
                    src="{{ section.settings.image | img_url: '750x' }}"
                    sizes="(min-width: {{ settings.page_width }}px) {{ settings.page_width | minus: 100 | divided_by: 3 }}px, (min-width: 750px) calc((100vw - 130px) / 2), calc((100vw - 50px) / 2)"
                    alt="{{ section.settings.image.alt | escape }}"
                    loading="lazy"
                    width="{{ section.settings.image.width }}"
                    height="{{ section.settings.image.height }}"
                  >
                {%- else -%}
                  {{ 'image' | placeholder_svg_tag: 'placeholder-svg' }}
                {%- endif -%}
              </div>
            </div>
            <div class="grid__item" >
              <div class="image-with-text__content image-with-text__content--{{ section.settings.height }}">
                {%- for block in section.blocks -%}
                  {% case block.type %}
                    {%- when 'heading' -%}
                      <h2 class="image-with-text__heading h1" {{ block.shopify_attributes }}>
                        {{ block.settings.heading | escape }}
                      </h2>
                    {%- when 'text' -%}
                      <div class="image-with-text__text rte" {{ block.shopify_attributes }}>{{ block.settings.text }}</div>
                    {%- when 'button' -%}
                      {%- if block.settings.button_label != blank -%}
                        <a{% if block.settings.button_link != blank %} href="{{ block.settings.button_link }}"{% endif %} class="button{% if block.settings.button_style_secondary %} button--secondary{% else %} button--primary{% endif %}"{% if block.settings.button_link == blank %} aria-disabled="true"{% endif %} {{ block.shopify_attributes }}>
                          {{ block.settings.button_label | escape }}
                        </a>
                      {%- endif -%}
                  {%- endcase -%}
                {%- endfor -%}
              </div>
            </div>
          </div>
        </div>
      </div>
</div>


{% schema %}
{
  "name": "BgI with text",
  "class": "spaced-section spaced-section--full-width",
  "settings": [
    {
      "type": "image_picker",
      "id": "image",
      "label": "t:sections.image-with-text.settings.image.label"
    },
    {
      "type": "select",
      "id": "height",
      "options": [
        {
          "value": "adapt",
          "label": "t:sections.image-with-text.settings.height.options__1.label"
        },
        {
          "value": "small",
          "label": "t:sections.image-with-text.settings.height.options__2.label"
        },
        {
          "value": "large",
          "label": "t:sections.image-with-text.settings.height.options__3.label"
        }
      ],
      "default": "adapt",
      "label": "t:sections.image-with-text.settings.height.label"
    },
    {
      "type": "select",
      "id": "color_scheme",
      "options": [
        {
          "value": "background-1",
          "label": "t:sections.image-with-text.settings.color_scheme.options__1.label"
        },
        {
          "value": "background-2",
          "label": "t:sections.image-with-text.settings.color_scheme.options__2.label"
        },
        {
          "value": "inverse",
          "label": "t:sections.image-with-text.settings.color_scheme.options__3.label"
        },
        {
          "value": "accent-1",
          "label": "t:sections.image-with-text.settings.color_scheme.options__4.label"
        },
        {
          "value": "accent-2",
          "label": "t:sections.image-with-text.settings.color_scheme.options__5.label"
        }
      ],
      "default": "background-1",
      "label": "t:sections.image-with-text.settings.color_scheme.label"
    },
    {
      "type": "select",
      "id": "layout",
      "options": [
        {
          "value": "image_first",
          "label": "t:sections.image-with-text.settings.layout.options__1.label"
        },
        {
          "value": "text_first",
          "label": "t:sections.image-with-text.settings.layout.options__2.label"
        }
      ],
      "default": "image_first",
      "label": "t:sections.image-with-text.settings.layout.label",
      "info": "t:sections.image-with-text.settings.layout.info"
    }
  ],
  "blocks": [
    {
      "type": "heading",
      "name": "t:sections.image-with-text.blocks.heading.name",
      "limit": 1,
      "settings": [
        {
          "type": "text",
          "id": "heading",
          "default": "Image with text",
          "label": "t:sections.image-with-text.blocks.heading.settings.heading.label"
        }
      ]
    },
    {
      "type": "text",
      "name": "t:sections.image-with-text.blocks.text.name",
      "limit": 1,
      "settings": [
        {
          "type": "richtext",
          "id": "text",
          "default": "<p>Pair text with an image to focus on your chosen product, collection, or blog post. Add details on availability, style, or even provide a review.</p>",
          "label": "t:sections.image-with-text.blocks.text.settings.text.label"
        }
      ]
    },
    {
      "type": "button",
      "name": "t:sections.image-with-text.blocks.button.name",
      "limit": 1,
      "settings": [
        {
          "type": "text",
          "id": "button_label",
          "default": "Button label",
          "label": "t:sections.image-with-text.blocks.button.settings.button_label.label",
          "info": "t:sections.image-with-text.blocks.button.settings.button_label.info"
        },
        {
          "type": "url",
          "id": "button_link",
          "label": "t:sections.image-with-text.blocks.button.settings.button_link.label"
        }
      ]
    }
  ],
  "presets": [
    {
      "name": "BgI with text",
      "blocks": [
        {
          "type": "heading"
        },
        {
          "type": "text"
        },
        {
          "type": "button"
        }
      ]
    }
  ]
}
{% endschema %}
